package com.open.capacity.prints.controller;

import com.open.capacity.commons.PageResult;
import com.open.capacity.commons.Result;
import com.open.capacity.prints.entity.BillGhyhjzd;
import com.open.capacity.prints.service.BillGhyhjzdService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 银行进账单
 *
 * @author 
 * @email 
 * @date 2021-04-07 09:40:45
 */
@RestController
@RequestMapping("ghyhjzds")
@Api(tags = "银行进账单")
public class BillGhyhjzdController {

    @Autowired
    private BillGhyhjzdService billGhyhjzdService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('bill_ghyhjzd:billghyhjzd:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = billGhyhjzdService.pageAll(params);
        return pageResult;
    }

    /**
    * 查询单条记录
    */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('bill_ghyhjzd:billghyhjzd:list')")
    public Result findById(String id) {
        return Result.succeed(billGhyhjzdService.findById(id));
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findByCprFullname")
    @PreAuthorize("hasAnyAuthority('bill_ghyhjzd:billghyhjzd:list')")
    public Result findByCprFullname(String cprFullname) {
        List<BillGhyhjzd> fullname = billGhyhjzdService.findByCprFullname(cprFullname);
        return Result.succeed(fullname);
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findBySkrFullname")
    @PreAuthorize("hasAnyAuthority('bill_ghyhjzd:billghyhjzd:list')")
    public Result findBySkrFullname(String skrFullname) {
        List<BillGhyhjzd> fullname = billGhyhjzdService.findBySkrFullname(skrFullname);
        return Result.succeed(fullname);
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('bill_ghyhjzd:billghyhjzd:save')")
    public Result save(@RequestBody @Valid BillGhyhjzd billGhyhjzd, String keyValue) {
    	 if(StringUtils.isEmpty(keyValue)) {
              keyValue = billGhyhjzdService.save(billGhyhjzd);
	     }else {
              billGhyhjzd.setId(keyValue);
              keyValue = billGhyhjzdService.update(billGhyhjzd);
	     }
        return Result.succeed(keyValue,"保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('bill_ghyhjzd:billghyhjzd:delete')")
    public Result delete(@PathVariable String  id) {
            billGhyhjzdService.delete(id);
        return Result.succeed("删除成功");
    }

}
